<template>
  <div class="header-container" v-if="isShow">
    <div class="header-height"></div>
    <div class="header-main">
      <span class="iconfont iconfanhui" @click="back"></span>
      <span class="title">{{ title }}</span>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      nowPath: null
    }
  },
  computed: {
    routesList () {
      return this.$router.options.routes
    },
    userInfo() {
      return this.$store.state.userData;
    },
    title () {
      if (this.routerData.type) {
        return this.routerData.type[this.$route.query.type]
      } else {
        return this.routerData.name
      }
    },
    isShow () {
      return this.routesList.filter(item => item.path === this.nowPath).length ? this.routesList.filter(item => item.path === this.nowPath)[0].header : false
    },
    routerData () {
      return this.routesList.filter(item => item.path === this.nowPath)[0]
    }
  },
  watch: {
    $route (newVal, oldVal) {
      this.nowPath = newVal.path
    }
  },
  mounted () {
    this.nowPath = this.$route.path
  },
  methods: {
    back () {
      if (this.title === '登陆' && !this.userInfo) {
        this.$router.push('/')
        return
      }
      window.history.back()
    }
  }
}
</script>

<style lang="scss">
.header-container {
  .header-height {
    height: 80px;
  }
  .header-main {
    position: fixed;
    top: 0;
    z-index: 100;
    width: 100vw;
    height: 80px;
    text-align: center;
    line-height: 80px;
    font-size: 35px;
    letter-spacing: 5px;
    font-weight: bold;
    // color: #fff;
    // background: linear-gradient(to right,#FC8F04,#F71C19);
    background: #fff;
    border-bottom: 1PX solid #EBEBEB;
    color: #000;
    .iconfont {
      font-size: 30px;
      position: absolute;
      left: 20px;
    }
  }
}
</style>